import os
from dotenv import load_dotenv

load_dotenv()

# Redis configuration
REDIS_HOST = os.getenv("REDIS_HOST", "127.0.0.1")
REDIS_PORT = int(os.getenv("REDIS_PORT", 6379))
REDIS_DB = int(os.getenv("REDIS_DB", 0))

def get_model_config(name: str) -> tuple[str, str | None, str | None, dict]:
    """
    Get model configuration based on name prefix.
    Returns tuple of (model, base_url, api_key, kwargs)
    
    Example:
        model, base_url, api_key, kwargs = get_model_config("BASIC")
    """
    name = name.upper()
    prefix = f"{name}_"
    
    model = os.getenv(f"{prefix}MODEL")
    base_url = os.getenv(f"{prefix}BASE_URL") 
    api_key = os.getenv(f"{prefix}API_KEY")
    
    # Collect all additional environment variables with the same prefix
    excluded_keys = [f"{prefix}MODEL", f"{prefix}BASE_URL", f"{prefix}API_KEY"]
    kwargs = {
        key[len(prefix):].lower(): value 
        for key, value in os.environ.items() 
        if key.startswith(prefix) and key not in excluded_keys
    }
    
    return model, base_url, api_key, kwargs